﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Project.Co_DataTransformationPrototype.UI
{
    public partial class AttributeMergeDialogBox : Form
    {
        private IList<EntityAttribute> attributeList;
        public string strNewAttributeName, strCombinationExpression;
        public SqlDbType newAttributeType;

        public AttributeMergeDialogBox(IList<EntityAttribute> selectedAttributes)
        {
            InitializeComponent();
            this.attributeList = selectedAttributes;
        }

        private void AttributeMergeDialogBox_Load(object sender, EventArgs e)
        {
            lstbSelectedAttributes.Items.AddRange(attributeList.ToArray());
            cboTypes.DataSource = Enum.GetValues(typeof(SqlDbType));
        }

        private void btnExecute_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(txtNewName.Text.Trim()) && cboTypes.SelectedValue != null && !String.IsNullOrEmpty(txtExpression.Text.Trim()) )
            {
                strNewAttributeName = txtNewName.Text;
                Enum.TryParse(cboTypes.SelectedValue.ToString(), out newAttributeType);
                strCombinationExpression = txtExpression.Text;
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Hide();
            }
            else
            {
                MessageBox.Show("Please enter an expression first.", "Merge Expression - Missing expression statements", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Hide();
        }
        
    }
}
